package org.example.top40;

public class main27 {
    //字符串相加
    //输入：num1 = "11", num2 = "123"
    //输出："134"
    //思路：两个指针，尾部开始相加，核心是num1.charAt(i)-'0':0
    //sb.append相加，最后一定要reverse()在toString
    public static void main(String[] args) {
        String num1="11";
        String num2="999";
        StringBuilder sb = new StringBuilder();
        int i=num1.length()-1;
        int j=num2.length()-1;
        int carry=0;
        while (i>=0||j>=0){
            int n1=i>=0?num1.charAt(i)-'0':0;
            int n2=j>=0?num2.charAt(j)-'0':0;
            int sum=n1+n2+carry;
            carry=sum/10;
            sb.append(sum%10);
            i--;
            j--;
        }
        if(carry!=0){
            sb.append(carry);
        }
        sb.reverse();
        String s = sb.toString();
        System.out.println(s);

    }
}
